//企业管理-企业列表
App.util.ns('Admin.Enterprise.Enterprise');
App.pages.add((function(){
    var NS = Admin.Enterprise.Enterprise;
    var page = new App.Page({
        name: 'enterprise/enterprise/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-handshake-o"></i>',
            content: '企业管理'
        }, {
            content: '企业列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/enterprise/enterprise',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                //showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '状态', width: '80px', items: [
                    [0, '停用'],
                    [1, '正常']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.enterprise.enterprise.create'},
                {parent: 'view', permission: 'op:admin.enterprise.enterprise.detail'},
                {parent: 'edit', permission: 'op:admin.enterprise.enterprise.update'},
                {type: 'inline', permission: 'gp:admin/enterprise/enterprise', name: '企业员工',
                    operation: function(dataTable, enterprise){
                        App.nav.open('enterprise/personnel/index', {
                            enterprise_id: enterprise.id,
                            enterprise_name: enterprise.name
                        });
                    }
                },
                {type: 'inline', permission: 'op:admin.enterprise.enterprise.open',
                    name: '开启', operation: {type: 'change', url: 'open'},
                    conditions: [['status', '0']]
                },
                {type: 'inline', permission: 'op:admin.enterprise.enterprise.close',
                    name: '关闭', operation: {type: 'change', url: 'close'},
                    conditions: [['status', '1']]
                },
                {parent: 'drop', permission: 'op:admin.enterprise.enterprise.delete'},
                {parent: 'multiDrop', permission: 'op:admin.enterprise.enterprise.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.enterprise.enterprise.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form),
                    onChange: function(form, data){
                        var htmljson = '';
                        var rule=data.rule;
                        if(!rule){
                            htmljson = '暂无信息';
                        }else{
                            rule = JSON.parse(rule);
                            htmljson += rule.title+'<br>';
                            var rulelist = rule.list;
                            for (var i =0;i<rulelist.length;i++){
                                htmljson += rulelist[i]+'<br>';
                            }
                        }
                        form.formItems['rule'].change(htmljson);
                    }
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());